import { _decorator, Component, Node, Sprite, SpriteFrame, tween, UIOpacity, UITransform, v3 } from 'cc';
import { GameMgr } from './GameMgr';
import { GameUtil } from '../util/GameUtil';
const { ccclass, property } = _decorator;

@ccclass('Manager/TransMgr')
export class TransMgr extends Component {

    private static inst: TransMgr = null
    public static get Inst(): TransMgr {
        return this.inst
    }

    @property(UITransform)
    private gc1UiTrans: UITransform = null
    @property(UITransform)
    private gc2UiTrans: UITransform = null
    @property(Node)
    private logo: Node = null

    @property(Sprite)
    private gc2: Sprite = null

    @property([SpriteFrame])
    private sptiteArr: SpriteFrame[] = [];

    private gc1OrgHeight: number = 0
    private gc2OrgHeight: number = 0

    protected onLoad(): void {
        GameMgr.mode = GameUtil.getTodayMode();
        this.gc2.spriteFrame = this.sptiteArr[GameMgr.mode];

        TransMgr.inst = this
        this.gc1OrgHeight = this.gc1UiTrans.height
        this.gc2OrgHeight = this.gc2UiTrans.height
        this.node.active = false
    }

    public fadeIn() {
        this.gc2.spriteFrame = this.sptiteArr[GameMgr.mode];
        return new Promise<void>((resolve, reject) => {
            // this.node.active = true
            // this.logo.setScale(v3(0, 0, 1))
            // tween(this.logo).delay(0.2).to(0.5, { scale: v3(1, 1, 1) }, { easing: 'backOut' }).start()
            // tween(this.gc1UiTrans).set({ height: 0 }).to(0.2, { height: this.gc1OrgHeight }).start()
            // const tw = tween(this.gc2UiTrans)
            // tw.set({ height: 0 })
            // tw.to(1, { height: this.gc2OrgHeight }, { easing: 'cubicOut' })
            // tw.call(() => {
            //     resolve()
            // })
            // tw.start()

            resolve()
        })
    }

    public fadeOut() {
        return new Promise<void>((resolve, reject) => {
            // tween(this.logo).to(0.5, { scale: v3() }, { easing: 'backIn' }).start()
            // tween(this.gc1UiTrans).delay(0.8).to(0.2, { height: 0 }).start()
            // const tw = tween(this.gc2UiTrans)
            // tw.to(1, { height: 0 }, { easing: 'cubicIn' })
            // tw.call(() => {
            //     this.node.active = false
            //     resolve()
            // })
            // tw.start()

            this.node.active = false
                resolve()
        })
    }


}


